<template>
    <div class="addAdult">
        <div class="add_item" @click="addAdult">+添加成人学员</div>
        <div class="dialog_from">
            <el-dialog title="添加成人学员信息" :modal=false :visible.sync="dialogFormVisible">
                <el-form :model="form">
                    <el-form-item label="昵称：" :label-width="formLabelWidth">
                        <el-input v-model="form.nickname" class="divided_2"></el-input>
                    </el-form-item>
                    <el-form-item label="手机号：" :label-width="formLabelWidth">
                        <el-input v-model="form.mobile" class="divided_2"></el-input>
                    </el-form-item>
                    <el-form-item label="真实姓名：" :label-width="formLabelWidth">
                        <el-input v-model="form.fullname" class="divided_2"></el-input>
                    </el-form-item>
                    <!-- <el-form-item label="发送信息给学员：" :label-width="formLabelWidth">
                        <el-radio-group  v-model="form.sendsms">
                            <el-radio label=1>是</el-radio>
                            <el-radio label=0>否</el-radio>
                        </el-radio-group>
                    </el-form-item> -->
                    <el-form-item label="QQ：" :label-width="formLabelWidth">
                        <el-input v-model="form.qq" class="divided_2"></el-input>
                    </el-form-item>
                    <el-form-item label="SKype：" :label-width="formLabelWidth">
                        <el-input v-model="form.skypenum" auto-complete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="Email：" :label-width="formLabelWidth">
                        <el-input v-model="form.email" auto-complete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="性别：" :label-width="formLabelWidth">
                        <el-radio-group  v-model="form.gender">
                            <el-radio label=1>男</el-radio>
                            <el-radio label=0>女</el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <el-form-item label="年龄段：" placeholder="选取年龄段" :label-width="formLabelWidth">
                        <el-select v-model="form.age">
                            <el-option v-for="(ageitem,a) in fromLabel.age" :key="a" :label="ageitem.attriname" :value="ageitem.attriid"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="英语水平：" placeholder="选取英语水平" :label-width="formLabelWidth">
                        <el-select v-model="form.studylevel">
                            <el-option v-for="(slitem,b) in fromLabel.studylevel" :key="b" :label="slitem.attriname" :value="slitem.attriid"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="英语分数：" :label-width="formLabelWidth">
                        <el-input v-model="form.highscore" class="divided_2"></el-input>
                    </el-form-item>
                    <el-form-item label="行业：" placeholder="选择一项行业" :label-width="formLabelWidth">
                        <el-select v-model="form.job">
                            <el-option v-for="(jobitem,c) in fromLabel.job" :key="c" :label="jobitem.attriname" :value="jobitem.attriid"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item :label-width="formLabelWidth" label="学习英语第一目标-课程：">
                        <el-checkbox-group v-model="form.wanttostudy">
                            <el-checkbox v-for="(ccitem,d) in fromLabel.curriculumType" :key="d" :label="ccitem.id" name="curriculumType">{{ccitem.title}}</el-checkbox>
                        </el-checkbox-group>
                    </el-form-item>
                    <el-form-item :label-width="formLabelWidth" label="学习英语第二目标-方面：">
                        <el-checkbox-group v-model="form.studyhigh">
                            <el-checkbox v-for="(studyhitem,e) in fromLabel.studyhigh" :key="e" :label="studyhitem.attriid" name="studyhigh">{{studyhitem.attriname}}</el-checkbox>
                        </el-checkbox-group>
                    </el-form-item>
                    <el-form-item :label-width="formLabelWidth" label="学习英语第三目标-知识：">
                        <el-checkbox-group v-model="form.studyextension">
                            <el-checkbox v-for="(studyexitem,f) in fromLabel.studyextension" :key="f" :label="studyexitem.attriid" name="studyextension">{{studyexitem.attriname}}</el-checkbox>
                        </el-checkbox-group>
                    </el-form-item>
                    <el-form-item :label-width="formLabelWidth" label="学习渠道：">
                        <el-checkbox-group v-model="form.studyfrom">
                            <el-checkbox v-for="(studyfitem,g) in fromLabel.studyfrom" :key="g" :label="studyfitem.attriid" name="studyfrom">{{studyfitem.attriname}}</el-checkbox>
                        </el-checkbox-group>
                    </el-form-item>
                    <el-form-item label="希望完成课程时间：" :label-width="formLabelWidth">
                        <el-select v-model="form.studyshijian">
                            <el-option v-for="(stshiitem,h) in fromLabel.studyshijian" :key="h" :label="stshiitem.attriname" :value="stshiitem.attriid"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="预算：" :label-width="formLabelWidth">
                        <el-select v-model="form.studymoney">
                            <el-option v-for="(stmitem,i) in fromLabel.studymoney" :key="i" :label="stmitem.attriname" :value="stmitem.attriid"></el-option>
                        </el-select>
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button class="dialog_close" @click="dialogFormVisible = false">取 消</el-button>
                    <el-button class="dialog_confirm" type="primary" @click="onSubmit">确 定</el-button>
                </div>
            </el-dialog>
        </div>
    </div>
</template>
<script>
import base from '../../api/base.js'
 export default {
    inject:['reload'],
    data() {
        return {
                dialogTableVisible: false,
                dialogFormVisible: false,
                form: {
                    nickname: '',
                    mobile:'',
                    fullname:'',
                    sendsms:'',
                    qq:'',
                    skypenum:'',
                    email:'',
                    gender:'',
                    age:'',
                    studylevel:'',
                    highscore:'',
                    job:'',
                    wanttostudy:[],
                    studyhigh:[],
                    studyextension:[],
                    studyfrom:[],
                    studyshijian: '',
                    studymoney:'',
                    delivery: false,
                },
                formLabelWidth: '180px',
                fromLabel:[],
                errorMsg:''
        };
    },
    methods:{
        addAdult(){
            this.dialogFormVisible = true
            this.clearAllDate()
        },
        clearAllDate(){
            this.form.nickname=''
            this.form.mobile=''
            this.form.fullname=''
            this.form.sendsms=''
            this.form.qq=''
            this.form.skypenum=''
            this.form.email=''
            this.form.gender=''
            this.form.age=''
            this.form.studylevel=''
            this.form.highscore=''
            this.form.job=''
            this.form.wanttostudy=[]
            this.form.studyhigh=[]
            this.form.studyextension=[]
            this.form.studyfrom=[]
            this.form.studyshijian=''
            this.form.studymoney=''
        },
        getData(){
            this.$axios({
                url: base.baseUrl+"/school/member/get-student-setting ",
                method: "POST",
                header: { 'content-type': 'application/x-www-form-urlencoded' },
                data:{
                    token: localStorage.token
                },
                transformRequest: [function (data) {
                    let ret = ''
                    for (let it in data) {
                        ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                    }
                    return ret
                }],
            }).then(res => {
                // console.log(res);
                if(res.data.code==200){
                    this.fromLabel=res.data.data;
                }else if(res.data.code==-2){
                    this.$router.push('/login')
                }
            });
        },
        onSubmit(){
            // console.log(this.form.studyfrom)
            this.$axios({
                url: base.baseUrl+"/school/member/set-adult-student",
                method: "POST",
                header: { 'content-type': 'application/x-www-form-urlencoded' },
                data:{
                    token: localStorage.token,
                    nickname: this.form.nickname,
                    mobile:this.form.mobile,
                    fullname:this.form.fullname,
                    sendsms:this.form.sendsms,
                    qq:this.form.qq,
                    skypenum:this.form.skypenum,
                    email:this.form.email,
                    gender:this.form.gender,
                    age:this.form.age,
                    studylevel:this.form.studylevel,
                    highscore:this.form.highscore,
                    job:this.form.job,
                    wanttostudy:this.form.wanttostudy,
                    studyhigh:this.form.studyhigh,
                    studyextension:this.form.studyextension,
                    studyfrom:this.form.studyfrom,
                    studyshijian: this.form.studyshijian,
                    studymoney:this.form.studymoney,
                },
                transformRequest: [function (data) {
                    let ret = ''
                    for (let it in data) {
                        ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                    }
                    return ret
                }],
            }).then(res => {
                if(res.data.code==-1){
                    this.alertTip(res.data.msg)
                }else if(res.data.code==200){
                    this.$alert('添加成功', '提示', {
                        confirmButtonText: '确定',
                        callback: action => {
                            this.reload()
                        }
                    });
                    this.dialogFormVisible = false;
                }
            });
        },
        alertTip(msg){
            this.$alert(msg, '提示', {
                confirmButtonText: '确定',
                callback: action => {
                    this.$message({
                        type: 'info',
                    });
                }
            });
        }
    },
    created(){
        this.getData()
    }
};
</script>

